package com.nassir.freemarker;

import freemarker.template.*;
import java.util.*;
import java.io.*;

public class Test {
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void main(String[] args) throws Exception {
        /* You should do this ONLY ONCE in the whole application life-cycle: */
        /* Create and adjust the configuration */
        Configuration cfg = new Configuration();
        cfg.setDirectoryForTemplateLoading(new File("templates/test"));
        cfg.setObjectWrapper(new DefaultObjectWrapper());
        /* You usually do these for many times in the application life-cycle: */
        /* Get or create a template */
        Template temp = cfg.getTemplate("test.ftl");
        /* Create a data-model */
        Map root = new HashMap();
        root.put("user", "Big Joe");
        Map latest = new HashMap();
        root.put("latestProduct", latest);
        latest.put("url", "products/greenmouse.html");
        latest.put("name", "green mouse");
        /* Merge data-model with template */
        User myuser = new User();
        myuser.setPassWord(null);
        myuser.setUserName("文境恋");
        root.put("myuser", myuser);
        root.put("type", 1);
        root.put("aaaa", "aaa");
        root.put("bb", 12);
        Writer out = new OutputStreamWriter(System.out);
        temp.process(root, out);
        out.flush();
    }
}